// src/api/cart.js
import request from '../util/request.js'

// 获取购物车列表
export function getCartList(params) {
    return request({
        url: '/user/shoppingCart/list',
        method: 'get',
        params
    })
}

// 添加商品到购物车
export function addToCart(data) {
    return request({
        url: '/user/shoppingCart/add',
        method: 'post',
        data
    })
}

// 更新购物车商品数量
export function updateCartItem(data) {
    return request({
        url: '/user/shoppingCart/update',
        method: 'put',
        data
    })
}

// 删除购物车商品
export function deleteCartItem(cartId) {
    return request({
        url: `/user/shoppingCart/delete/${cartId}`,
        method: 'delete'
    })
}

// 批量删除购物车商品
export function batchDeleteCartItems(cartIds) {
    return request({
        url: '/user/shoppingCart/batchDelete',
        method: 'post',
        data: cartIds
    })
}

// 清空购物车
export function clearCart(userId) {
    return request({
        url: '/user/shoppingCart/clear',
        method: 'delete',
        params: { userId }
    })
}
